package com.ncs.nc.controller;

import com.ncs.nc.entity.Customer;
import com.ncs.nc.entity.Order;
import com.ncs.nc.entity.ResultObject;
import com.ncs.nc.service.CustomerService;
import com.ncs.nc.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author LEI
 * 在这个Controller里写对应的CRUD操作
 * 但是，也要先把对应的Mapper和Service写完
 */
@RestController
@RequestMapping("/customer")
public class CustomerController {

    @Autowired
    private CustomerService cs;
    @Autowired
    private ResultObject ro;

    //获取菜单
    @CrossOrigin(origins = "http://127.0.0.1:8848")
    @RequestMapping("/all")
    public ResultObject<Customer> getOrders(){
        ResultObject ro=new ResultObject<>();
        ro.setStatus("200");
        List<Customer> auths=cs.list();
        ro.setData(auths);
        return ro;
    }

    //全查
    @RequestMapping("/customers")
    @CrossOrigin(origins = "http://127.0.0.1:8848")
    public ResultObject all(){
        ro.setMsg("查询成功");
        ro.setStatus("200");
        ro.setData(cs.list());
//        ro.setData(cs.getAllGoods());
        return ro;
    }
//
//    //单查
//    @CrossOrigin(origins = "http://127.0.0.1:8848")
//    @RequestMapping("/one/{cId}")
//    public ResultObject getById(@PathVariable("GoodsId") Long GoodsId){
//        ro.setMsg("查询成功");
//        ro.setStatus("200");
//        ro.setData(ds.getById(GoodsId));
//        return ro;
//    }

    /**
     * 添加
     * @param customer
     * @return
     */
    @CrossOrigin(origins = "http://127.0.0.1:8848")
    @RequestMapping("/add")
    public ResultObject add(@RequestBody Customer customer){
//        System.out.println(customer);
        //这里赋成null值
//        customer.setCustomerId("");
        //再次打印customer
        System.out.println(customer);
        ResultObject ro=new ResultObject<>();
        boolean isAdded=cs.save(customer);
        if (isAdded){
            ro.setMsg("更新成功");
            ro.setStatus("200");
        }else{
            ro.setMsg("更新失败");
            ro.setStatus("500");
        }
        ro.setData(isAdded);
        return ro;
    }



//    //更新
//    @CrossOrigin(origins = "http://127.0.0.1:8848")
//    @RequestMapping("/update")
//    public Object update(@RequestBody Goods Goods){
//        ResultObject ro=new ResultObject<>();
//        ro.setMsg("更新成功");
//        ro.setStatus("200");
//        ro.setData(ds.updateById(Goods));
//        return ro;
//    }
//

//
//    //删除
//    @CrossOrigin(origins = "http://127.0.0.1:8848")
//    @RequestMapping("/del/{cId}")
//    public Object deleteById(@PathVariable("GoodsId") Long GoodsId){
//        ResultObject ro=new ResultObject<>();
//        ro.setMsg("删除成功");
//        ro.setStatus("200");
//        ro.setData(ds.removeById(GoodsId));
//        return ro;
//    }

    //条件查

    //分页查

    //排序



}
